package com.admin.business.portalWebsite.venusOaAdvertisement;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 广告列表
 * @create: 2023-11-22 16:07:28
 **/
@Service("venusOaAdvertisementService")
@Slf4j
public class VenusOaAdvertisementService{

    @Resource
    VenusOaAdvertisementDao venusOaAdvertisementDao;

    /**
     * 添加广告列表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - code:订单id
     *                   - user_id:添加人
     *                   - advertisement_name:广告名称
     *                   - platform:平台 1:门户网 2:助业app 3:员工app 4:业主app
     *                   - position:位置关联id
     *                   - show_pictures:广告图片
     *                   - hyperlink:超链接
     *                   - start_time:开始时间
     *                   - end_time:结束时间
     *                   - money:金额
     *                   - person_charge:负责人
     *                   - person_charge_tel:负责人电话
     *                   - payment:支付类型(1 微信、2支付宝、3 现金、4 银行卡、5 支票 、6银行对私账户 7、银行对公账户
     *                   - update_time:修改时间
     *                   - begin_time:创建时间
     *                   - state:状态 0:正常 1:删除
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return addVenusOaAdvertisement(CDO cdoRequest) {
        venusOaAdvertisementDao.addVenusOaAdvertisement(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新广告列表数据
     *
     * @param cdoRequest - id:主键id
     *                   - code:订单id
     *                   - user_id:添加人
     *                   - advertisement_name:广告名称
     *                   - platform:平台 1:门户网 2:助业app 3:员工app 4:业主app
     *                   - position:位置关联id
     *                   - show_pictures:广告图片
     *                   - hyperlink:超链接
     *                   - start_time:开始时间
     *                   - end_time:结束时间
     *                   - money:金额
     *                   - person_charge:负责人
     *                   - person_charge_tel:负责人电话
     *                   - payment:支付类型(1 微信、2支付宝、3 现金、4 银行卡、5 支票 、6银行对私账户 7、银行对公账户
     *                   - update_time:修改时间
     *                   - begin_time:创建时间
     *                   - state:状态 0:正常 1:删除
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return updateVenusOaAdvertisementById(CDO cdoRequest) {
        venusOaAdvertisementDao.updateVenusOaAdvertisementById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除广告列表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return deleteVenusOaAdvertisementById(CDO cdoRequest){
        int count = venusOaAdvertisementDao.deleteVenusOaAdvertisementById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除广告列表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return deleteVenusOaAdvertisement(CDO cdoRequest) {
        int count = venusOaAdvertisementDao.deleteVenusOaAdvertisement(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取广告列表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return getVenusOaAdvertisementById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaAdvertisementDao.getVenusOaAdvertisementById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取广告列表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return getVenusOaAdvertisementListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaAdvertisementDao.getVenusOaAdvertisementListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaAdvertisementDao.getVenusOaAdvertisementCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取广告列表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return getVenusOaAdvertisementListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaAdvertisementDao.getVenusOaAdvertisementListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaAdvertisementDao.getVenusOaAdvertisementCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
